package org.jpass.dc.business.conpiler;

import java.io.IOException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jpass.dc.business.project.logic.FileService;

public class BuildMessage {
	
	private Log log = LogFactory.getLog(BuildMessage.class);
	
	private String errorFilePath = null;
	//private String outFilePath = null;
	private String message = null;
	
	public BuildMessage(String outPutFilePath) {
		this.errorFilePath = outPutFilePath;
		//this.outFilePath = outPutFilePath;
	}

	public BuildMessage(String errorFilePath, String outFilePath) {
		this.errorFilePath = errorFilePath;
		//this.outFilePath = outFilePath;
	}

	/**
	 * 取得编译后的错误信息
	 * @param errorLogPath 编译出错信息的文件路径
	 * @return
	 */
	public String getErrorMessage() {
		String msg = null;
		try {
			msg = new FileService().readFile(errorFilePath);
			message = this.formatErrorMsg(errorFilePath.substring(0, errorFilePath.lastIndexOf("/")), msg);
		} catch (IOException e) {
			log.error("编译出错信息的文件路径不存在" + errorFilePath);
		}
		
		return message;
	}
	
	public String formatErrorMsg(String regex, String msg) {
		regex = regex.replaceAll("/", "\\\\\\\\") + "\\\\";
		return msg.replaceAll(regex, "");
	}

}
